package bean;

import java.util.Vector;

public class Page {
    // 页面容纳的记录数目
    private int size;
    // 页面总数
    private int total;
    // 页面索引，取值范围是从1到total的值
    private int index;
    // 记录总数
    private int recordTotal;
    // 查询条件
    private Test condition;
    // 查询得到的数据
    private Vector<Test> data;

    public int getSize() {
        return size;
    }

    private void setSize(int size) {
        if (size < 0) {
            this.size = Math.abs(size);
        } else if (size > 0) {
            this.size = size;
        } else {
            this.size = 10;
        }
    }

    public int getTotal() {
        return total;
    }

    private void setTotal(int recordTotal) {
        int total = recordTotal / size;
        this.total = (recordTotal % size == 0) ? total : total + 1;
    }

    public int getIndex() {
        return index;
    }

    // 修改index值后，自动设置data为空
    public void setIndex(int index) {
        if (this.index != index && index > 0) {
            this.index = index;
            setData(null);
        }
    }

    public int getRecordTotal() {
        return recordTotal;
    }

    // 设置记录总数后，自动设置页面总数
    public void setRecordTotal(int recordTotal) {
        this.recordTotal = recordTotal;
        setTotal(this.recordTotal);
    }

    public Vector<Test> getData() {
        return data;
    }

    public Test getCondition() {
        return condition;
    }

    public void setCondition(Test condition) {
        this.condition = condition;
    }

    public void setData(Vector<Test> data) {
        this.data = data;
    }

    public Page() {
        size = 10;
        index = 1;
        data = new Vector<>();
    }

    public Page(int index) {
        size = 10;
        setIndex(index);
        data = new Vector<>();
    }

    public Page(int size, int index) {
        setSize(size);
        setIndex(index);
        data = new Vector<>();
    }
}
